{template '../Public/header'}
<script type="text/javascript" src="__PUBLIC__/Js/jquery.validate.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/jQuery.validate.message_cn.js"></script>
<link rel="Stylesheet" type="text/css" href="__PUBLIC__/Js/jmodal/jquery.jmodal.css" />
<script type="text/javascript" src="__PUBLIC__/Js/jmodal/jquery.jmodal.js"></script>
{template '../Public/nav'}
<div class="w990 clear">
        <div id="main">
            <div class="main_l">
                <div id="main_l_l" class="clear">
                    <h2 class="login_t">会员注册</h2>
                    <ul class="clear">
                    <form action="{echo reUrl('User/reg')}" method="post" id="reg_form" name="reg_form">
                    <table width="100%" border="0" class="login_form">
  <tr>
    <td width="100" align="right">帐号：</td>
    <td><input name="nick" id="nick" type="text" style="width:200px;" onblur="check_nick_valid();" /><label class="error2" id="tip_nick"></label></td>
  </tr>
  <tr>
    <td width="100" align="right">E-mail：</td>
    <td><input name="email" id="email" type="text" style="width:200px;" /></td>
  </tr>
  <tr>
    <td align="right">密码：</td>
    <td><input name="pw" id="pw" type="password" style="width:200px;" onblur="check_nick_valid();" /></td>
  </tr>
  <tr>
    <td align="right">确认密码：</td>
    <td><input name="confirm_pw" id="confirm_pw" type="password" style="width:200px;" /></td>
  </tr>
  <!--{if $captcha}-->
  <tr>
    <td align="right">验证码：</td>
    <td><input type="text" name="verify" size="8" />
	<img src="__ROOT__/index.php?g=Public&m=Public&a=verifycode&mt={$mt}" align="absmiddle" alt="captcha" height="{$_CFG.captcha_height}" width="{$_CFG.captcha_width}" style="vertical-align: middle;cursor: pointer;" onClick="this.src='__ROOT__/index.php?g=Public&m=Public&a=verifycode&mt='+Math.random()" id="verifyImg" /></td>
  </tr>
  <!--{/if}-->
  <tr>
    <td align="right">&nbsp;</td>
    <td><input name="agree" id="agree" type="checkbox" value="1" />&nbsp;<a href="__ROOT__/Html/policy.html" target="_blank" id="label_agree">同意注册协议</a></td>
  </tr>
  <tr>
    <td align="right">&nbsp;</td>
    <td><input type="submit" value="注册" name="commit" id="signup-submit" class="formbutton"></td>
  </tr>
</table>
<input name="hash" type="hidden" value="{$hash}" />
</form>
				</ul>
                </div>
            </div>
            <div class="main_r" style="width: 320px;">
    <ul class="sidebar">
            

        <li class="yellow">
            <h3>已有{$_CFG['site_name']}帐号？</h3>
            <div class="sidebar_s clear">
                <ul class="twocol user_link">
                    <li><a class="login_btn" href="{echo reUrl('User/login')}"></a></li>
                </ul>
            </div>
        </li>
   
             </ul>
</div>
        </div>
    </div>
<script type="text/javascript">
var g = '{GROUP_NAME}';
var m = '{MODULE_NAME}';
var a = '{ACTION_NAME}';
var reg_url = "{echo reUrl('User/reg')}";
var u_index_url = "{echo reUrl('User/index')}";
var dosubmit = false;
var root_path = '__ROOT__';
<!--{if $captcha}-->
var captcha = true;
<!--{else}-->
var captcha = false;
<!--{/if}-->
function fleshVerify()
{
	var time = new Date().getTime();
	$("#verifyImg").attr('src',root_path+"/index.php?g=Public"+"&m=Public"+"&a=verifycode"+"&mt="+time);
}
function check_nick_valid()
{
	var nick = $('#nick').val();
	if(nick == ''){
		$('#tip_nick').text('');
		return false;
	}
	var url = root_path+"/index.php?g="+g+"&m="+m+"&ajax=1&a=check_nick_valid&nick="+encodeURIComponent(nick);
		$.getJSON(url, function(data){
									if(data.status == 0){
										$('#tip_nick').html('该帐号已存在');
										dosubmit = false;
									}else{
										$('#tip_nick').html('<font color="green">该帐号可以使用</font>');
										dosubmit = true;
									}
									});
}
function reg()
{
	if(! dosubmit) return false;
	$.ajax({
		url: reg_url,
		type:"POST",
		cache: false,
		data:$("#reg_form").serialize(),
		dataType:"json",
		error: function(){
			
		},
		success: function(result){
			if(result.status==1){
				var tips = '注册成功<br>现在您可以会员身份登陆';
				if(result.data.verifyed==0){
					tips = '我们已经给您的邮箱发送了一封验证邮件，请登陆您的邮箱查看。';
				}
				$.fn.jmodal({
                    data: {},
                    title: '温馨提示',
                    content: tips,
                    buttonText: { ok: '确定', cancel: '' },
                    fixed: false,
					marginTop: 200,
					okEvent: function(data, args) {
						if(result.data.verifyed==1){
                        	window.location.href = u_index_url;
						}else{
							window.location.href = root_path+"/index.php?g="+g+"&m="+m+"&a=reverify&&uid="+result.info;
						}
                    }
                });
			}else{
				$.fn.jmodal({
                    data: {},
                    title: '温馨提示',
                    content: result.info,
                    buttonText: { ok: '确定', cancel: '' },
                    fixed: false,
					marginTop: 200,
					okEvent: function(data, args) {
						if(captcha){
							fleshVerify();
						}
                        args.hide();
                    }
                });
			}
		}
	});
}
$(document).ready(function() {
			$("#reg_form").validate({
						 errorPlacement:function(error,element) {
     												if (element.attr("name") == "agree"){
       													error.insertAfter("#label_agree");
													}else{
														error.insertAfter(element);
													}},
						 submitHandler:function(form){
							 						reg();
													return false;
						 						}
						 });
			$('#nick').rules('add', {
						 		required: true,
								rangelength: [2,20]
						});
			$('#email').rules('add', {
						 		required: true,
								email: true
						});
			$('#pw').rules('add', {
						 		required: true,
								rangelength: [6,15]
						});
			$('#confirm_pw').rules('add', {
						 		required: true,
								equalTo: '#pw',
								rangelength: [6,15]
						});
			$('#agree').rules('add', {
						 		required: true
						});
});
</script>
{template "../Public/footer"}